package org.cinvestav.computacion.matias.onlyangel.j3d;
import javax.media.j3d.Appearance;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.ColoringAttributes;
import javax.media.j3d.LineArray;
import javax.media.j3d.Shape3D;
import javax.media.j3d.TriangleArray;
import javax.vecmath.Color3f;
import javax.vecmath.Point3f;

import com.sun.j3d.utils.geometry.Box;


public class Fondo extends BranchGroup {
	public Fondo(){
		createFondo();
	}
	public Fondo(int x, int y,int w, int h){
		int n;
		LineArray horizontal = new LineArray((y-1)*2,TriangleArray.COORDINATES|TriangleArray.COLOR_3);
		LineArray vertical = new LineArray((x-1)*2,TriangleArray.COORDINATES|TriangleArray.COLOR_3);
		for (n=0;n<y-1;n++){
			horizontal.setCoordinate(n*2, new Point3f(-1f, -1f+(float)n/y*2+(float)2/y, 0.011f));
			horizontal.setCoordinate((n*2)+1, new Point3f(1f, -1f+(float)n/y*2+(float)2/y, 0.011f));
			horizontal.setColor(n*2, new Color3f(0.0f, 1.0f, 0.0f));
			horizontal.setColor((n*2)+1, new Color3f(0.0f, 1.0f, 0.0f));
		}
		for (n=0;n<x-1;n++){
			vertical.setCoordinate(n*2, new Point3f(-1f+(float)n/x*2+(float)2/x, -1, 0.011f));
			vertical.setCoordinate((n*2)+1, new Point3f(-1f+(float)n/x*2+(float)2/x, 1, 0.011f));
			vertical.setColor(n*2, new Color3f(0.0f, 1.0f, 0.0f));
			vertical.setColor((n*2)+1, new Color3f(0.0f, 1.0f, 0.0f));
		}
		Shape3D fH = new Shape3D(horizontal);
		Shape3D fV = new Shape3D(vertical);
		
		addChild(fH);
		addChild(fV);
		createFondo();
	}
	public void createGrid(){
		
	}
	public void createFondo(){
		Appearance apr = new Appearance();
		apr.setColoringAttributes(new ColoringAttributes(new Color3f(100,150,200),ColoringAttributes.NICEST));
		addChild(new Box(1f,1f,0.01f,apr));
	}
}
